<?php
/**
 * Created by PhpStorm.
 * User: yxs
 * Date: 2017/6/5
 * Time: 17:18
 */

namespace model;

use think\Model;

class ShopOrder extends Model
{
    protected $auto = ['op_time'];
    protected $insert = ['order_sn', 'order_time'];
    protected $resultSetType = 'collection';
    public function shopOrderItem(){
        $this->hasMany("ShopOrderItem","order_id");
    }

    public function setOrderTimeAttr()
    {
        return time();
    }
    public function setOpTimeAttr()
    {
        return time();
    }
    public function getOrderTimeAttr($value)
    {
        return date("Y-m-d H:i",$value);
    }
    public function getFlagStatusAttr($value)
    {
        $text = ["未配送", "正在配送", "申请取消", "确定取消", "取消订单", "货到付款(未配送)", "正在配送(货到付款)","已收货"];
        return ["value" => $value, "text" => $text[$value]];
    }
    public function setOrderSnAttr()
    {
        $weimiao = str_pad(substr(gettimeofday()['usec'], -3, 3), 3, 0, STR_PAD_LEFT); //获取微秒后3位数,不足补0
        $orderNo = date('YmdHis') . $weimiao;
        return $orderNo;
    }
}